package com.example.vp.service.impl;

import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.common.holder.UserHolder;

import com.example.vp.domian.enetity.History;
import com.example.vp.mapper.HistoryMapper;
import com.example.vp.service.HistoryService;
import org.springframework.stereotype.Service;

@Service
public class HistoryServiceImpl extends ServiceImpl<HistoryMapper, History> implements HistoryService {
    @Override
    public void addHistory(Long videoId) {
        Long userId = UserHolder.getUserId();
        History history = new History();
        history.setUserId(userId);
        history.setVideoId(videoId);
        history.setCreatedTime(DateTime.now());
        history.setUpdatedTime(DateTime.now());
        saveOrUpdate(history);
    }

    @Override
    public void delectById(Long videoId) {
        Long userId = UserHolder.getUserId();
        remove(new LambdaQueryWrapper<History>().eq(History::getUserId,userId).eq(History::getVideoId,videoId));
    }

    @Override
    public void delectHistory() {
        Long userId = UserHolder.getUserId();
        remove(new LambdaQueryWrapper<History>().eq(History::getUserId,userId));
    }
}
